<template>
	<view class="resourceList">
		<uni-row style="margin-top: 8rpx;">
			<uni-col :span="12" style="padding-right: 5rpx;">
				<uni-data-select placeholder="所有仓库" v-model="queryParams.warehouseId" :localdata="warehouseList" style="background-color: #fff;">
				</uni-data-select>
			</uni-col>
			<uni-col :span="12">
				<uni-easyinput style="background-color: #fff;" suffixIcon="search" v-model="queryParams.params.materialName" 
					placeholder="查询物料" @iconClick="queryClick"></uni-easyinput>
			</uni-col>
			
		</uni-row>
		<uni-row >
					  <uni-col :span="22" style="padding-left: 5rpx;padding-top: 1rpx;">
					  	<button type="primary" size="mini"  @click="addButtonClick">新增</button>
					  </uni-col>
					  <uni-col :span="2" style="padding-top: 7rpx;">
					  	<uni-icons type="list" size="32"></uni-icons>
					  </uni-col>
		</uni-row>
		
		
		<view v-for="(item,index) in manufactureIntoList" style="margin-top: 10rpx;">
			<uni-row class="resourceList-uni-row">
				<text style="font-size: 18px;font-weight:bold;">
					入库单:&nbsp;&nbsp;&nbsp;{{item.manufactureInto.number}}
				</text>
			</uni-row>
			<uni-row class="resourceList-uni-row">
				<text class="resourceList-text">
					入库时间:&nbsp;&nbsp;&nbsp;{{item.manufactureInto.intoDate}}
				</text>
			</uni-row>
			<uni-row class="resourceList-uni-row">
				<text class="resourceList-text">
					入库产品:&nbsp;&nbsp;&nbsp;{{item.materialName}}
				</text>
			</uni-row>
			<uni-row class="resourceList-uni-row">
				<text class="resourceList-text">
					型号:&nbsp;&nbsp;&nbsp;{{item.specification}}
				</text>
			</uni-row>
			<uni-row class="resourceList-uni-row">
				<text class="resourceList-text">
					入库数量:&nbsp;&nbsp;&nbsp;{{item.quantity}} &nbsp;&nbsp;&nbsp;({{item.materialUnitName}})
				</text>
			</uni-row>
			<uni-row class="resourceList-uni-row">
				<text class="resourceList-text">
					入库仓库:&nbsp;&nbsp;&nbsp;{{item.manufactureInto.warehouseName}}
				</text>
			</uni-row>
			<uni-row class="resourceList-uni-row">
				<text class="resourceList-text">
					交货人:&nbsp;&nbsp;&nbsp;{{item.manufactureInto.delivererName}}
				</text>
			</uni-row>
			<uni-row class="resourceList-uni-row" style="margin-bottom: 20rpx;">
				<text class="resourceList-text">
					备注:&nbsp;&nbsp;&nbsp;{{item.manufactureInto.remark}}
				</text>
			</uni-row>
		</view>
		<uni-load-more :status="loadStatus"  />
		<manufactureIntoForm ref="manufactureIntoForm"  > </manufactureIntoForm>
	</view>
	
</template>

<script>
	import { listManufactureInto, getManufactureInto, delManufactureInto, addManufactureInto, updateManufactureInto } from "@/api/warehouse/manufactureInto.js"
	import manufactureIntoForm  from "@/pages/warehouse/manufactureInto/form.vue";
	import {
		getUserProfile
	} from "@/api/system/user"
	import {
		getDicts
	} from "@/api/system/dict/data";
	import {
		listWarehouse
	} from "@/api/warehouse/warehouse";
	import { getMaterial } from "@/api/masterdata/material";
	import { getUnit } from '@/api/masterdata/unit'
	import {  listForMobile,getInfoByEntryId,getWorkOrder} from "@/api/production/workOrder";
	export default {
		components: { manufactureIntoForm },
		onLoad: function (option) {
				if(typeof(option.workOrderEntryId)!='undefined'){
					this.queryParams.workOrderEntryId = option.workOrderEntryId;
				}
		},
		data() {
			return {
				queryParams: {
					pageSize: 5,
					pageNum: 1,
					params: {},
					workOrderEntryId:""
				},
				loadStatus: "more",
				//完工入库列表
				manufactureIntoList: [],
				user: {},
				warehouseList: [],
			}
		},
		created() {
			this.getUser();
			this.getList();
			this.getWarehouse();
		},
		onReachBottom() {
			 this.clickLoadMore()
		 },
		methods: {
			getWarehouse(){
				listWarehouse({pageSize: 99999}).then(response => {
					let list = [];
					list = response.rows;
					for (let i = 0; i < list.length; i++) {
						list[i].value = list[i].id;
						list[i].text = list[i].name;
						this.warehouseList.push(list[i]);
					}
				});
			},
			/** 查询列表 */
			getList() {
				this.queryParams.delivererId=this.user.userId
				listManufactureInto(this.queryParams).then(response => {
					let total =response.total;
					let list = response.rows;
					//已查询出来的和新查询的 大于等于total总页数，表示no-more
					if (list.length+this.manufactureIntoList.length >=total) {
						this.loadStatus = "no-more"
					} else {
						this.loadStatus = "more"
					}
					
					if (this.manufactureIntoList.length > 0) {
						this.manufactureIntoList = this.manufactureIntoList.concat(list)
					} else {
						this.manufactureIntoList = list;
					}
				})
			},
			getUser() {
				getUserProfile().then(response => {
					this.user = response.data
				})
			},
			addButtonClick(){
				let id =this.queryParams.workOrderEntryId;
				if(id!=''){
					this.$refs.manufactureIntoForm.form.workOrderEntryId=id;
					
					getInfoByEntryId(id).then( res =>{
						
						let entry = res.data.workOrderEntryList[0];
						this.$refs.manufactureIntoForm.isShowFlag=false;
						let _this=this
						console.log("entry===========>",entry)
						getMaterial(entry.reportMaterialId==null?entry.pickMaterialId:entry.reportMaterialId).then(resB =>{
							getUnit(resB.data.unitId).then(resC =>{
								
								_this.$refs.manufactureIntoForm.form.manufactureIntoEntryList=[
									{	
										materialId: entry.reportMaterialId==null?entry.pickMaterialId:entry.reportMaterialId,
										materialName: entry.reportMaterialName==null?entry.pickMaterialName:entry.reportMaterialName,
										specification: entry.reportSpecification==null?entry.pickSpecification:entry.reportSpecification,
										quantity: entry.reportQuantity==null?entry.pickQuantity:entry.reportQuantity,
										materialNumber:resB.data.number,
										materialUnitId:resB.data.unitId,
										materialUnitName:resC.data.name
									}
								]
								
							})
						})
						
					})
				}
				this.$refs.manufactureIntoForm.openPopup();
			},
			queryClick(){
				this.queryParams.pageNum = 1
				this.manufactureIntoList = []
				this.getList();
			},
			clickLoadMore() {
				if (this.loadStatus === "no-more") {
					return;
				}
				this.loadStatus = "loading"
				this.queryParams.pageNum += 1;
				this.getList();
			}
		},
	}
</script>

<style>
	.resourceList-uni-row {
		margin-bottom: 8rpx;
	}

	.resourceList-text {
		font-size: 16px;
	}

	.resourceList {
		margin-left: 10px;

	}
	.example-body {
		/* #ifndef APP-NVUE */
		display: block;
		/* #endif */
		padding: 10rpx 10rpx 0;
		overflow: hidden;
	}
</style>
